package com.peanut.baby.comm;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.peanut.baby.R;

import java.util.List;

/**
 * 排行榜Adapter
 * Created by taransky on 16/5/10.
 */
public class DialogListAdapter extends BaseAdapter {
    private Context ctx;
    private List<String> users;
    private LayoutInflater inflater;


    public DialogListAdapter(Context ctx, List<String> users) {
        this.ctx = ctx;
        this.users = users;
        inflater = LayoutInflater.from(ctx);

    }

    @Override
    public int getCount() {
        return users == null ? 0 : users.size();
    }

    @Override
    public Object getItem(int position) {
        return users == null ? null : users.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.layout_dialog_list, null);
            holder = new ViewHolder();

            holder.label = (TextView) convertView.findViewById(R.id.list_item_text);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        holder.label.setText(users.get(position));

        return convertView;
    }

    class ViewHolder {
        TextView label;

    }
}
